package org.ycx.upms.dao.auto;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.ycx.upms.dao.model.SecRolePermission;
import org.ycx.upms.dao.model.SecRolePermissionExample;

import java.util.List;

public interface SecRolePermissionMapper {
    @SelectProvider(type=SecRolePermissionSqlProvider.class, method="countByExample")
    long countByExample(SecRolePermissionExample example);

    @DeleteProvider(type=SecRolePermissionSqlProvider.class, method="deleteByExample")
    int deleteByExample(SecRolePermissionExample example);

    @Delete({
        "delete from sec_role_permission",
        "where ROLE_ID = #{roleId,jdbcType=INTEGER}",
          "and PERMISSION_ID = #{permissionId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(@Param("roleId") Integer roleId, @Param("permissionId") Integer permissionId);

    @Insert({
        "insert into sec_role_permission (ROLE_ID,PERMISSION_ID,INHERIT)",
        "values (#{roleId,jdbcType=INTEGER},#{permissionId},#{inherit,jdbcType=INTEGER})"
    })
    int insert(SecRolePermission record);

    @InsertProvider(type=SecRolePermissionSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="permissionId", before=false, resultType=Integer.class)
    int insertSelective(SecRolePermission record);

    @SelectProvider(type=SecRolePermissionSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="ROLE_ID", property="roleId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="PERMISSION_ID", property="permissionId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="INHERIT", property="inherit", jdbcType=JdbcType.INTEGER)
    })
    List<SecRolePermission> selectByExample(SecRolePermissionExample example);

    @Select({
        "select",
        "ROLE_ID, PERMISSION_ID, INHERIT",
        "from sec_role_permission",
        "where ROLE_ID = #{roleId,jdbcType=INTEGER}",
          "and PERMISSION_ID = #{permissionId,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="ROLE_ID", property="roleId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="PERMISSION_ID", property="permissionId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="INHERIT", property="inherit", jdbcType=JdbcType.INTEGER)
    })
    SecRolePermission selectByPrimaryKey(@Param("roleId") Integer roleId, @Param("permissionId") Integer permissionId);

    @UpdateProvider(type=SecRolePermissionSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") SecRolePermission record, @Param("example") SecRolePermissionExample example);

    @UpdateProvider(type=SecRolePermissionSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") SecRolePermission record, @Param("example") SecRolePermissionExample example);

    @UpdateProvider(type=SecRolePermissionSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(SecRolePermission record);

    @Update({
        "update sec_role_permission",
        "set INHERIT = #{inherit,jdbcType=INTEGER}",
        "where ROLE_ID = #{roleId,jdbcType=INTEGER}",
          "and PERMISSION_ID = #{permissionId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(SecRolePermission record);
}